package org.idea.spring.ioc.bean;

import org.springframework.beans.factory.FactoryBean;

/**
 * @Author idea
 * @Date created in 10:32 下午 2020/5/12
 */
public class UserFactoryBean implements FactoryBean<User> {

    private int age;

    public UserFactoryBean(int age) {
        this.age = age;
    }


    @Override
    public User getObject() throws Exception {
        //可能对于某个bean的具体实现过程非常复杂
        User user = this.builder(age);
        user.setIsVerify(user.getAge() > 18);
        return user;
    }

    @Override
    public Class<?> getObjectType() {
        return User.class;
    }


    private User builder(int age) {
        User user = new User();
        user.setId(-1);
        user.setAge(11);
        user.setSex(1);
        user.setAge(age);
        return user;
    }
}
